local skynet = require "skynet.manager"
local server_config = dofile(skynet.getenv("server_config"))

local max_client = server_config.gateway_max_client
local watchdog_port = server_config.gateway_listen_port

local server_id = tonumber(skynet.getenv "server_id")

skynet.start(function()
	skynet.error("Server start")
	if not skynet.getenv "daemon" and server_config.no_cotainer then
		local console = skynet.newservice("console")
	end
	local debug_listen_ip = "127.0.0.1"
	if not server_config.no_cotainer then
		debug_listen_ip = '0.0.0.0'
	end
	skynet.newservice("debug_console",debug_listen_ip, server_config.debug_port)

	local kafka_queue = skynet.newservice('kafka_queue')
	skynet.name('.kafka_queue',kafka_queue)

	local msg_handler = skynet.newservice("msg_handler")
	skynet.name('.msg_handler',msg_handler)

	local watchdog = skynet.newservice("watchdog")
	skynet.name('.watchdog',watchdog)
	skynet.call(watchdog, "lua", "start", {
		port = watchdog_port,
		maxclient = max_client,
		nodelay = true,
		server_id = server_id,
		server_name = skynet.getenv "server_name",
		msg_handler = msg_handler,
	})
	skynet.error("Watchdog listen on", watchdog_port)

	skynet.exit()
end)

